package com.cs.base.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import java.util.List;

/**
 * @ClassName: BaseFragmentPagerAdapter
 * @Date: 2021/6/17
 * @Author: CS
 * @Description: 适配androidx.viewpager.widget.ViewPager
 */
public class BaseFragmentPagerAdapter<F extends Fragment> extends FragmentStatePagerAdapter {

    private final List<F> fragmentList;

    public BaseFragmentPagerAdapter(@NonNull FragmentManager fm, List<F> list) {
        super(fm, FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        fragmentList = list;
    }


    @NonNull
    @Override
    public F getItem(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }
}
